home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / c / tcombo.exe / TEST.CPP < prev    next >
C/C++ Source or Header  |  1992-11-18  |  4KB  |  141 lines

  1. /*************************************************************************/
  2. /*                                                                       */
  3. /* Test program file for TComboBox and TStaticInputLine classes.         */
  4. /*                                                                       */
  5. /* Copyright (c) 1992, Vincent J. Dentice                                */
  6. /* All rights reserved                                                   */
  7. /*                                                                       */
  8. /*************************************************************************/
  9.  
  10. #define Uses_ifpstream
  11. #define Uses_ofpstream
  12. #define Uses_TApplication
  13. #define Uses_TButton
  14. #define Uses_TDeskTop
  15. #define Uses_TDialog
  16. #define Uses_TEvent
  17. #define Uses_TInputLine
  18. #define Uses_TKeys
  19. #define Uses_TMenuBar
  20. #define Uses_TMenuItem
  21. #define Uses_TRect
  22. #define Uses_TStatusLine
  23. #define Uses_TStatusItem
  24. #define Uses_TStatusDef
  25. #define Uses_TStringCollection
  26. #define Uses_TSubMenu
  27. #include <tv.h>
  28.  
  29. #define Uses_TComboBox
  30. #define Uses_TStaticInputLine
  31. #include "tcombobx.h"
  32. #include "tsinputl.h"
  33.  
  34. const int cmNewDialog = 200; // assign new command values
  35.  
  36.  
  37. class TMyApp : public TApplication {
  38.    public:
  39.       TMyApp();
  40.       static TStatusLine *initStatusLine( TRect r );
  41.       static TMenuBar *initMenuBar( TRect r );
  42.       virtual void handleEvent( TEvent& event);
  43.       void newDialog();
  44. };
  45.  
  46. static short winNumber = 0;          // initialize window number
  47.  
  48.  
  49. TMyApp::TMyApp() : TProgInit(&TMyApp::initStatusLine,
  50.                  &TMyApp::initMenuBar,
  51.                  &TMyApp::initDeskTop)
  52. {
  53. }
  54.  
  55.  
  56. TStatusLine *TMyApp::initStatusLine(TRect r)
  57. {
  58.    r.a.y = r.b.y - 1;     // move top to 1 line above bottom
  59.    return new TStatusLine( r,
  60.       *new TStatusDef( 0, 0xFFFF ) +
  61.      *new TStatusItem( 0, kbF10, cmMenu ) +
  62.      *new TStatusItem( "~Alt-X~ Exit", kbAltX, cmQuit ) +
  63.      *new TStatusItem( "~Alt-F3~ Close", kbAltF3, cmClose )
  64.       );
  65. }
  66.  
  67. TMenuBar *TMyApp::initMenuBar( TRect r )
  68. {
  69.    r.b.y = r.a.y + 1;    // set bottom line 1 line below top line
  70.    return new TMenuBar( r,
  71.       *new TSubMenu( "~F~ile", kbAltF )+
  72.      *new TMenuItem( "~D~ialog", cmNewDialog, kbF3, hcNoContext, "F3" )+
  73.       newLine()+
  74.      *new TMenuItem( "E~x~it", cmQuit, cmQuit, hcNoContext, "Alt-X" )
  75.       );
  76. }
  77.  
  78. void TMyApp::handleEvent(TEvent& event)
  79. {
  80.    TApplication::handleEvent(event); // act like base!
  81.    if(event.what == evCommand) {
  82.       switch(event.message.command) {
  83.      case cmNewDialog:      // but respond to additional commands
  84.         newDialog();        // define action for cmMyNewWin
  85.         break;
  86.      default:
  87.         return;
  88.       }
  89.       clearEvent( event );       // clear event after handling
  90.    }
  91. }
  92.  
  93. void TMyApp::newDialog()
  94. {
  95.    TDialog    *pd;
  96.    TInputLine *tv;
  97.    TStringCollection *list;
  98.    struct {
  99.       char line1[128];
  100.       TCollection *list1;
  101.       char line2[128];
  102.       TCollection *list2;
  103.    } data;
  104.  
  105.    list = new TStringCollection(5,2);
  106.  
  107.    list->insert(newStr("Test 1"));
  108.    list->insert(newStr("Test 2"));
  109.  
  110.    TRect r(2,1,27,10);
  111.  
  112.    pd = new TDialog(r, "Test Dialog");
  113.    if (pd) {
  114.       tv = new TInputLine(TRect(2,1,20,2), 128);
  115.       pd->insert(tv);
  116.       pd->insert(new TComboBox(TRect(20,1,21,2), tv, list));
  117.  
  118.       tv = new TStaticInputLine(TRect(2,3,20,4), 128, list);
  119.       pd->insert(tv);
  120.       pd->insert(new TComboBox(TRect(20,3,21,4), tv, list));
  121.  
  122.       pd->insert(new TButton(TRect( 1,6,11,8), "~O~K", cmOK, bfDefault));
  123.       pd->insert(new TButton(TRect(12,6,22,8), "Cancel", cmCancel, bfNormal));
  124.    }
  125.  
  126.    pd->selectNext(False);
  127.    deskTop->execView(pd);
  128.  
  129.    pd->getData(&data);
  130.  
  131.    destroy(pd);
  132.    destroy(list);
  133. }
  134.  
  135. int main()
  136. {
  137.    TMyApp myApp;
  138.    myApp.run();
  139.    return 0;
  140. }
  141.